<template>
  <div>
    <h1>SSM 与 Vue 参数传递</h1>
    <form @submit.prevent="submitForm">
      <label for="name">姓名:</label>
      <input v-model="user.name" id="name" type="text" />

      <label for="age">年龄:</label>
      <input v-model="user.age" id="age" type="number" />

      <button type="submit">提交</button>
    </form>

    <p>返回结果: {{ response }}</p>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name:"HomeA",
  data() {
    return {
      user: {
        name: "",
        age: 0,
      },
      response: null,
    };
  },
  methods: {
    async submitForm() {
      try {
        const res = await axios.post("http://localhost:8080/add", this.user);
        this.response = res.data;
      } catch (error) {
        console.error(error);
      }
    },
  },
};
</script>

<style>
</style>
